package thread;

/*
 * @author zzr
 * @date: 2025/03/31  18:46
 * @description:
 */
public class ThreadDemo32 {
    public static void main(String[] args) {
        Object lockerA = new Object();
        Object lockerB = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (lockerA) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (lockerB) {
                    System.out.println("t1线程拿到了两把锁");
                }
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (lockerB) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (lockerA) {
                    System.out.println("t2线程拿到了两把锁");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
